package kth.csc.inda;

import static org.junit.Assert.*;

import org.junit.Test;

public class ListGraphTest {

	@Test
	public void testListGraph() {
		int size = 8;
        UndirectedGraph g = new ListGraph(size);
        g = new ListGraph(0);
	}

	@Test
	public void testNumVertices() {
        UndirectedGraph g = new ListGraph(8);
        assertTrue(g.numVertices()==8);
        g = new ListGraph(2);
        assertTrue(g.numVertices()==2);
	}

	@Test
	public void testNumEdges() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1);
        g.addEdge(2, 2);
        g.addEdge(0, 3);
        g.addEdge(1, 4);
        g.addEdge(3, 4);
        g.addEdge(5, 3);
        g.addEdge(6, 7);
        assertTrue(g.numEdges()==7);
        
        g = new ListGraph(10);
        g.addEdge(0, 1);
        g.addEdge(2, 2);
        assertTrue(g.numEdges()==2);
        g = new ListGraph(10);
        assertTrue(g.numEdges()==0);
	}

	@Test
	public void testDegree() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1);
        g.addEdge(0, 2);
        g.addEdge(0, 3);
        g.addEdge(0, 4);
        g.addEdge(3, 4);
        g.addEdge(5, 3);
        g.addEdge(6, 7);
        assertTrue(g.degree(0)==4);
        g = new ListGraph(10);
        g.addEdge(1, 1);
        g.addEdge(2, 2);
        g.addEdge(3, 3);
        g.addEdge(4, 4);
        g.addEdge(3, 4);
        g.addEdge(5, 3);
        g.addEdge(6, 7);
        assertTrue(g.degree(0)==0);
	}

	@Test
	public void testAdjacentVertices() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1);
        g.addEdge(0, 2);
        VertexIterator it = g.adjacentVertices(0);
        while(it.hasNext()){
        	assertTrue(it.next()==1&&it.next()==2);
        }
	}

	@Test
	public void testAreAdjacent() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1);
        g.addEdge(0, 2);
        assertTrue(g.areAdjacent(0, 1));
        assertTrue(g.areAdjacent(0, 2));
	}

	@Test
	public void testEdgeCost() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1,5);
        g.addEdge(0, 2,6);
        assertTrue(g.edgeCost(0, 1)==5);
        assertTrue(g.edgeCost(0, 2)==6);
	}

	@Test
	public void testAddEdgeIntInt() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1);
        g.addEdge(0, 2);
	}

	@Test
	public void testAddEdgeIntIntInt() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1, 8);
        g.addEdge(0, 2, 6);
	}

	@Test
	public void testRemoveEdge() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1, 8);
        g.removeEdge(0, 1);
        assertTrue(g.numEdges()==0);
	}

	@Test
	public void testToString() {
		UndirectedGraph g = new ListGraph(10);
        g.addEdge(0, 1);
        g.addEdge(0, 2);
        g.addEdge(0, 3);
        g.addEdge(0, 4);
        g.addEdge(3, 4);
        g.addEdge(5, 3);
        g.addEdge(6, 7);
        assertTrue(("Vertices: 10, Edges: {(0,1), (0,2), (0,3), (0,4), (3,4), (3,5), (6,7)}").equals(g.toString()));
	}

}
